/** @file               sw_mutex.h
 *  @copyright          Copyright (C) 2006-2026 flyfish (tenggui_fu@126.com)
 *  @brief              This file is part of the swallow library
 *  @author             $Author: flyfish $
 *  @version            $Rev: 385 $
 *  @date               $Date: 2016-12-22 00:12:05 +0800 (周四, 22 12月 2016) $
 */
#ifndef __SW_MUTEX_H__
#define __SW_MUTEX_H__

#if !defined(WIN32) || defined(__MINGW32__) || defined(SW_V_WITH_PTHREAD)
#include <pthread.h>
#endif

#ifdef __cplusplus
extern "C" {
#endif

#if defined(WIN32) && !defined(__MINGW32__) && !defined(SW_V_WITH_PTHREAD)
typedef CRITICAL_SECTION *SW_MUTEX;
#define SW_INVALID_MUTEX (SW_MUTEX)NULL
#else
typedef pthread_mutex_t *SW_MUTEX;
#define SW_INVALID_MUTEX (SW_MUTEX)NULL
#endif

typedef enum _SW_MUTEX_TYPE
{
    SW_MT_NORMAL,
    SW_MT_RECURSIVE,
    SW_MT_INVALID = -1
}SW_MUTEX_TYPE;

SW_API SW_RET SW_InitMutexAPI(SW_VOID);
SW_API SW_RET SW_RunMutexAPI(SW_VOID);
SW_API SW_RET SW_StopMutexAPI(SW_VOID);
SW_API SW_RET SW_ExitMutexAPI(SW_VOID);
SW_API SW_MUTEX SW_CreateMutex(SW_VOID);
SW_API SW_MUTEX SW_CreateMutexEx(SW_MUTEX_TYPE type);
SW_API SW_RET SW_DeleteMutex(SW_MUTEX mtx);
SW_API SW_RET SW_LockMutex(SW_MUTEX mtx);
SW_API SW_RET SW_TryLockMutex(SW_MUTEX mtx);
SW_API SW_RET SW_TimeLockMutex(SW_MUTEX mtx, SW_UINT32 msec);
SW_API SW_RET SW_UnlockMutex(SW_MUTEX mtx);

#ifdef __cplusplus
}
#endif

#endif

